<template>
	<view class="list">
		<!-- 切换 -->
		<view class="list_nav flex-row-between">
			<view v-for="(item,index) in navList" :key="index" class="flex-column-center" @click="Onnav(item)">
				<view class="font13 font-333333" style="position: relative;" :style="item.show?'color: #00b7ee;':''">
					{{item.title}}
					<view class="badge" v-if="parseInt(item.badge||0)>0">{{item.badge||0}}</view>
				</view>
				<view class="nav_border" v-if="item.show"></view>
			</view>
		</view>
		<!-- 数据 -->
		<view class="list_bos">
			<LoadMore ref="LoadMore" id="LoadMore" :diffHeight="88" :initData="initData" @dataRefresh='dataRefresh'>
				<text></text>
				<view class="shop_list" v-for="(item,index) in orderlist" :key="index"
					@click="gotoDetails(item,index)">
					<view class="order_title">订单编号：{{item.order_code}}</view>
					<view class="status">
						<image :src="'/static/lj/drug/rectangle_'+item.typestatus+'.png'" mode="aspectFill"></image>
						<view class="inner">{{item.typename}}</view>
					</view>
					<view class="outer">
						<view class="item u-flex" v-for="(item1,index1) in item.goods_list" :key="index1">
							<view class="pic">
								<image :src="$base.cdn(item1.goods_img)" mode="aspectFill"></image>
							</view>
							<view class="con u-flex-1">
								<view class="u-flex u-flex-between">
									<view class="tit">
										{{item1.goods_name}}
										<text>{{item1.spec_name}}</text>
									</view>
									<view class="price">￥{{item1.goods_price}}x{{item1.number}}</view>
								</view>
								<view class="scon">
									用法用量：{{item1.frequencys}}，{{item1.consumptions}}，{{item1.usages}}
								</view>
								<view class="scon">
									备注：{{item1.remark||'--'}}
								</view>
							</view>
						</view>
						<view class="hj">
							共{{item.total_num}}件商品
							<text>合计：￥{{(parseFloat(item.total_price)+parseFloat(item.express_price)).toFixed(2)}} (运费￥{{item.express_price}})</text>
						</view>
					</view>
					<view class="foot u-flex u-flex-between u-flex-y-center">
						<view>
							<view v-if="item.typestatus=='dsh'&&item.shipping_type==2">到店自提</view>
						</view>
						<view class="u-flex" @click.stop>
							<view class="btn-fillet-o" @click.stop="Oncancel(item)" v-if="item.typestatus=='shz'||item.typestatus=='wtg'||item.typestatus=='dzf'">取消订单</view>
							<view class="btn-fillet" @click="gotoDetails(item,index)" v-if="item.typestatus=='dzf'">去支付</view>
							
							<button class="btn-fillet-o" open-type="contact" v-if="item.typestatus=='dfh'">退款请联系客服</button>
							
							<block v-if="item.typestatus=='dsh'">
								<view class="btn-fillet" @click.stop="Ontrue(item)" v-if="item.shipping_type==1">确认收货</view>
								<view class="btn-fillet" @click.stop="Ontrue(item)" v-else>核销收货</view>
							</block>
							
							<view class="btn-fillet-o" @click.stop="Ondel(item)" v-if="item.typestatus=='yqx'||item.typestatus=='ywc'">删除订单</view>
							
							<!-- <view class="btn-fillet" @click="Oncancel(item)" v-if="item.typestatus=='ywc'">再次购买</view> -->
						</view>
					</view>
				</view>
			</LoadMore>
		</view>

	</view>
</template>

<script>
	import LoadMore from "@/components/loadMore.vue";
	export default {
		components: {
			LoadMore
		},
		data() {
			return {
				wxcode: '', //
				imgFullUrl: this.$store.state.http_img, //图片地址
				//传参数据
				initData: {
					url: 'mylistPrescription', //接口
					//data里得传参
					param: {
						pay_status: '',
						order_status: ''
					},
				},
				navList: [{
						title: '全部',
						code: 1,
						badge: 0,
						show: true
					},
					{
						title: '待支付',
						code: 2,
						badge: 0,
						show: false
					},
					{
						title: '待发货',
						code: 3,
						badge: 0,
						show: false
					},
					{
						title: '待收货',
						code: 4,
						badge: 0,
						show: false
					},
					{
						title: '已完成',
						code: 5,
						badge: 0,
						show: false
					}
				],
				orderlist: [],
				
				curorder: null,
			}
		},
		onLoad: function(options) {},
		onShow(){
			let that = this
			
			this.$Http({
				url: 'getUserInfo',
				type: 'POST',
				data: {}
			}).then(res => {
				if (res.code == 1) {
					this.navList[1].badge = res.data.drug_can_pay_count||0
				}
			})
		},
		methods: {
			//切换
			Onnav(e) {
				this.navList.forEach(item => {
					item.show = false
					if (item.code == e.code) {
						item.show = true
					}
				})
				//全部
				if (e.code == 1) {
					this.initData.param.pay_status = ''
					this.initData.param.order_status = ''

				}
				//待付款
				if (e.code == 2) {
					this.initData.param.pay_status = 2
					this.initData.param.order_status = ''
				}
				//待发货
				if (e.code == 3) {
					this.initData.param.pay_status = 1
					this.initData.param.order_status = 10
				}
				//已发货
				if (e.code == 4) {
					this.initData.param.pay_status = 1
					this.initData.param.order_status = 20
				}
				//已完成
				if (e.code == 5) {
					this.initData.param.pay_status = 1
					this.initData.param.order_status = 30
				}
				this.$refs.LoadMore.oncutRefresh(this.initData)
			},
			//数据返回
			dataRefresh(e) {
				e.forEach(item => {
					if(item.status=='normal'){
						item.typename = '审核中'
						item.typestatus = 'shz'
					}else if(item.status=='reject'){
						item.typename = '未通过'
						item.typestatus = 'wtg'
					}else if(item.status=='hidden'){
						item.typename = '已取消'
						item.typestatus = 'yqx'
					}else{
						//已支付
						if (item.pay_status == 1) {
							if (item.order_status == 10) {
								item.typename = '待发货'
								item.typestatus = 'dfh'
							}
							if (item.order_status == 20) {
								item.typename = '待收货'
								item.typestatus = 'dsh'
							}
							if (item.order_status == 30) {
								item.typename = '已完成'
								item.typestatus = 'ywc'
							}
						}
						//未支付
						if (item.pay_status == 2) {
							if (item.order_status == 10) {
								item.typename = '待支付'
								item.typestatus = 'dzf'
							}
						}
					}
				})
				this.orderlist = e
			},
			//跳转
			goNext(url) {
				uni.navigateTo({
					url: url
				});
			},
			gotoDetails(item,index){
				var that = this
				uni.navigateTo({
					url: '/pagesA/drug/info?id='+item.id,
					events: {
						// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
						changeStatusEvent: function(data) {
							that.$refs.LoadMore.oncutRefresh(that.initData)
						}
					},
				})
			},
			
			// 取消订单
			Oncancel(item) {
				let that = this
				uni.showModal({
					title: '操作提示',
					confirmText: '确定',
					confirmColor: '#6ccbb6',
					cancelText: '取消',
					content: '您确定要取消吗',
					success: function(res) {
						if (res.confirm) {
							that.$Http({
								url: 'cancelPrescription',
								show: true,
								data: {
									doctor_prescription_id: item.id
								},
								type: 'post',
							}).then(res => {
								if (res.code == 1) {
									that.$refs.LoadMore.oncutRefresh(that.initData)
								}
							});
						}
					}
				});
			},
			// 删除订单
			Ondel(item) {
				let that = this
				uni.showModal({
					title: '操作提示',
					confirmText: '确定',
					confirmColor: '#6ccbb6',
					cancelText: '取消',
					content: '您确定要删除吗',
					success: function(res) {
						if (res.confirm) {
							that.$Http({
								url: 'delPrescription',
								show: true,
								data: {
									doctor_prescription_id: item.id
								},
								type: 'post',
							}).then(res => {
								if (res.code == 1) {
									that.$refs.LoadMore.oncutRefresh(that.initData)
								}
							});
						}
					}
				});
			},
			// 确认收货 退款
			Ontrue(e, name) {
				let that = this
				uni.showModal({
					title: '操作提示',
					confirmText: '确定',
					confirmColor: '#6ccbb6',
					cancelText: '取消',
					content: '您确定要收货吗',
					success: function(res) {
						if (res.confirm) {
							that.$Http({
								url: 'receivingPrescription',
								show: true,
								data: {
									doctor_prescription_id: e.id
								},
								type: 'post',
							}).then(res => {
								if (res.code == 1) {
									that.$refs.LoadMore.oncutRefresh(that.initData)
								}
							});
						}
					}
				});
			},
			
			onkf(){},
		}
	}
</script>

<style lang="less">
	@import url("style.less");
</style>
